import React, { useState, useEffect } from 'react';
import {StyleSheet, Text, View, Image, Alert} from 'react-native';

const CartScreen = () => {
  interface Data {
    id: number;
    url: string;
    title: string
  }
  const [data, setData] = useState<Data[]>([]);

  const fetchData = async () => {
    try {
      Alert.alert('开始加载数据');
      const response = await fetch('https://ibs-bj.com/prod-api/offcialsite/banner/list');
      const requestData = await response.json();
      
      requestData.data.forEach((item: any) => {
        const { id, url, title, body } = item;
        const listItem: Data = {
          id,
          title,
          url
        };
        setData((prevData) => [listItem, ...prevData]);
      })
      Alert.alert('数据加载完成');
    } catch (error) {
      console.error('Error fetching data:', error);
      Alert.alert('获取数据失败', JSON.stringify(error));
    }
  };

  useEffect(() => {
    fetchData();
  }, []);

  return (
    <View style={{height: 10000}}>
       <Image
          source={ {uri: 'http://127.0.0.1:49152/static/1705541400587/capture.jpg' }}
          style={{ width: 200, height: 200 }}
        />
      <Text>CartScreen</Text>
      <Text>{JSON.stringify(data)}</Text>
     
    </View>
  );
};

const styles = StyleSheet.create({});

export default CartScreen;
